package com.shelpe.services.sustainer.configuration;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.boot.autoconfigure.batch.BasicBatchConfigurer;
import org.springframework.boot.autoconfigure.batch.BatchProperties;
import org.springframework.core.task.SimpleAsyncTaskExecutor;

public class SustainerBatchConfigurer extends BasicBatchConfigurer {
	
	public SustainerBatchConfigurer(BatchProperties properties, DataSource dataSource, EntityManagerFactory entityManagerFactory) {
		super(properties, dataSource, entityManagerFactory);
	}
	
	@Override
	protected JobLauncher createJobLauncher() throws Exception {
		SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
		SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
		executor.setThreadGroupName("sustainer-batch-job");
		executor.setThreadNamePrefix("sustainer");
		executor.setConcurrencyLimit(10);
		jobLauncher.setTaskExecutor(executor);
		jobLauncher.setJobRepository(this.getJobRepository());
		jobLauncher.afterPropertiesSet();
		return jobLauncher;
	}
	
}
